<template>
	<view class="page">
		<view class="title f_48 navy_blue">全部学习资讯</view>
		<view  class="com_learning_scroll_view">
			<information-bar :list="languageList" :index="langeIndex" @bindTitleBar="getBarIndex"/>
		</view>
		<notice-list :list="noticeListData" @bind-notice-view="bindNotice"/>
		<load-more :status="loasStatus"></load-more>
	</view>
</template>

<script>
const app = getApp();
import noticeList from '@/components/notice-list/index.vue'; //资讯列表
import informationBar from '@/components/information-bar/index.vue'; // 资讯标题栏
import loadMore from '@/components/loadmore/index.vue';

import { comPageMixinFun } from '@/static/mixins/comPageCommon.js';
import { commonMixinFun } from '@/static/mixins/common.js';
import API from '@/static/api/index.js';
export default {
	components: {
		informationBar,
		noticeList,
		loadMore
	},
	mixins: [commonMixinFun, comPageMixinFun],
	data() {
		return {
			loasStatus:'empty',
			info_cate_id:0,
			langeIndex:0,
			languageList:[],
			noticeListData:[],
			page:1,
			size:10,
			totals:0,
			isRequest:false
		};
	},
	onLoad(option) {
		this.langeIndex=option.index
		this.languageList=JSON.parse(decodeURIComponent(option.list))
	},
	onShow(){
		if(this.languageList.length>0){
			this.info_cate_id = this.languageList[this.langeIndex].info_cate_id;
			this.getTInfomationList()
		}else{
			// 获取语种列表
			API.getTLanguageList().then(({code,data})=>{
				app._log(code,data)
				if(code==1){
					this.languageList = data.languages
					this.info_cate_id = this.languageList[this.langeIndex||0].info_cate_id;
					this.getTInfomationList()
				}else{
					this.languageList = []
				}
			}).catch(err=>{
				this.languageList = []
			})
		}
	},
	methods:{
		getBarIndex(index){
			this.page=1
			this.langeIndex=index
			this.info_cate_id = this.languageList[index].info_cate_id
			this.getTInfomationList()
		},
		getTInfomationList(){
			let {info_cate_id,page,size,isRequest,noticeListData,loasStatus,totals}=this
			if(!isRequest&&(page==1||noticeListData.length<totals)){
				this.isRequest=true
				if(loasStatus!='nomore'){
					loasStatus='loading'
				}
				API.getTInfomationList(info_cate_id,page,size).then(({code,data,msg})=>{
					if(code==1){
						app._log(code,data,msg)
						let tempArr = (page==1?[]:noticeListData).concat(data.infomations);
						if(tempArr.length>0){
							this.totals = data.total
							this.page+=(data.total>=tempArr.length?0:1)
							this.noticeListData = tempArr
						}
						this.loasStatus=tempArr.length==0?'empty':(data.total>=tempArr.length?'nomore':'getmore')
					}else{
						if(page==1&&code==405){
							this.noticeListData = [];
							this.loasStatus='empty'
						}else{
							if(code==405){
								this.loasStatus='nomore'
							}else{
								this.loasStatus='error'
								this.showToast(msg||'请求失败')
							}
							
						}
					}
				this.isRequest=false
				}).catch(err=>{
				this.isRequest=false
				this.loasStatus='error'
					this.showToast(err.msg||'加载失败')
				})
			}
		},
	
		// 点击咨询
		bindNotice(i) {
			app._log('点击了第',i)
			let {languageList,langeIndex,noticeListData}=this
			this.pageTo('/pages/teacher/article_details/index',{id:noticeListData[i].infomation_id,index:langeIndex,list:JSON.stringify(languageList)})
		},
	},
	onReachBottom() {
		this.getTInfomationList()
	}
};
</script>

<style lang="scss" scoped>
.page{
	background-color: #fff;
	
}
.page > .title {
	width: 750rpx;
	line-height: 98rpx;
	padding-left: 48rpx;
}
	.com_learning_scroll_view{
		/* #ifndef APP-PLUS-NVUE */
		position: -webkit-sticky;
		/* #endif */
		position: sticky;
		// top: var(--window-top);
		z-index: 99;
		top: 0;
	}
</style>
